home *** CD-ROM | disk | FTP | other *** search
/ PC Users 1999 May / Cd Pc Users extra 20 mayo 1999.iso / Prog / Inst / MsChart / Mschart3 / FORM1.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-07-02  |  2.8 KB  |  102 lines

  1. VERSION 5.00
  2. Object = "{02B5E320-7292-11CF-93D5-0020AF99504A}#1.0#0"; "MSCHART.OCX"
  3. Begin VB.Form Form1 
  4.    Caption         =   "Form1"
  5.    ClientHeight    =   5040
  6.    ClientLeft      =   1095
  7.    ClientTop       =   825
  8.    ClientWidth     =   7200
  9.    LinkTopic       =   "Form1"
  10.    PaletteMode     =   1  'UseZOrder
  11.    ScaleHeight     =   5040
  12.    ScaleWidth      =   7200
  13.    Begin MSChartLib.MSChart Chart1 
  14.       Height          =   4815
  15.       Left            =   120
  16.       OleObjectBlob   =   "Form1.frx":0000
  17.       TabIndex        =   0
  18.       Top             =   120
  19.       Width           =   6975
  20.    End
  21. Attribute VB_Name = "Form1"
  22. Attribute VB_GlobalNameSpace = False
  23. Attribute VB_Creatable = False
  24. Attribute VB_PredeclaredId = True
  25. Attribute VB_Exposed = False
  26. Option Explicit
  27. Private Values() As Single
  28. Private NumPoints As Integer
  29. Private Sub LoadData()
  30. Dim db As Database
  31. Dim qdef As QueryDef
  32. Dim rs As Recordset
  33. Dim dbname As String
  34. Dim i As Integer
  35.     ' Open the database.
  36.     dbname = App.Path
  37.     If Right$(dbname, 1) <> "\" Then dbname = dbname & "\"
  38.     dbname = dbname & "data.mdb"
  39.     Set db = OpenDatabase(dbname)
  40.     ' Get the records.
  41.     Set qdef = db.CreateQueryDef("", _
  42.         "SELECT Year, Value FROM YearlyValues")
  43.     Set rs = qdef.OpenRecordset(dbOpenSnapshot)
  44.     ' See how many records there are.
  45.     rs.MoveLast
  46.     NumPoints = rs.RecordCount
  47.     ReDim Values(1 To NumPoints, 1 To 2)
  48.     ' Load the data.
  49.     rs.MoveFirst
  50.     For i = 1 To NumPoints
  51.         Values(i, 1) = Format$(rs!Year, "yyyy")
  52.         Values(i, 2) = rs!Value
  53.         rs.MoveNext
  54.     Next i
  55.     rs.Close
  56.     db.Close
  57. End Sub
  58. Private Sub MakeData()
  59. Const NUM_POINTS = 40
  60. Dim db As Database
  61. Dim dbname As String
  62. Dim i As Integer
  63. Dim the_year As Date
  64. Dim the_value As Single
  65. Dim sql As String
  66.     ' Open the database.
  67.     dbname = App.Path
  68.     If Right$(dbname, 1) <> "\" Then dbname = dbname & "\"
  69.     dbname = dbname & "data.mdb"
  70.     Set db = OpenDatabase(dbname)
  71.     ' Delete any old data.
  72.     sql = "DELETE FROM YearlyValues"
  73.     db.Execute sql
  74.     ' Create a bunch of data.
  75.     the_year = #1/1/60#
  76.     the_value = 1000
  77.     For i = 1 To 38
  78.         sql = "INSERT INTO YearlyValues VALUES (#" & _
  79.             Format$(the_year) & "#, " & _
  80.             Format$(the_value) & ")"
  81.         db.Execute sql
  82.         
  83.         the_year = DateAdd("yyyy", 1, the_year)
  84.         the_value = the_value + Rnd * 2
  85.     Next i
  86.     db.Close
  87. End Sub
  88. Private Sub Form_Load()
  89. Const MAKING_DATA = False
  90.     If MAKING_DATA Then
  91.         MakeData
  92.         Unload Me
  93.     Else
  94.         LoadData
  95.         ' Send the data to the chart.
  96.         Chart1.chartType = VtChChartType2dXY
  97.         Chart1.RowCount = NumPoints
  98.         Chart1.ColumnCount = 2
  99.         Chart1.ChartData = Values
  100.     End If
  101. End Sub
  102.